package cn.project.lemontree.controller;

import cn.project.lemontree.aop.SystemControllerLog;
import cn.project.lemontree.bean.Child;
import cn.project.lemontree.bean.Diary;
import cn.project.lemontree.bean.Task;
import cn.project.lemontree.bean.Teacher;
import cn.project.lemontree.service.DiaryService;
import cn.project.lemontree.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/diary")
@Api(tags = "日记管理模块")
@CrossOrigin  //跨域访问
public class DiaryController {
    @Resource
    private DiaryService diaryService;

    @ApiOperation("分页查询日记信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="page",value="页码",required=true,dataTypeClass = int.class,example = "1"),
            @ApiImplicitParam(name="size",value="每页行数",required=true,dataTypeClass = int.class,example = "10"),
            @ApiImplicitParam(name="theme",value="主题",required=false,dataTypeClass = String.class)
    })
    @GetMapping("/listpage")
    public CommonResult<Map<String ,Object>> listpage(int page,int size,String theme){
        Map<String ,Object> map = new HashMap<>();
        map.put("data" ,diaryService.listpage(page,size,theme));
        map.put("count",diaryService.count(theme));
        map.put("page",page);
        return CommonResult.success(map);
    }

    @ApiOperation("分页查询特定家长儿童日记信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="page",value="页码",required=true,dataTypeClass = int.class,example = "1"),
            @ApiImplicitParam(name="size",value="每页行数",required=true,dataTypeClass = int.class,example = "10"),
            @ApiImplicitParam(name="theme",value="主题",required=false,dataTypeClass = String.class),
            @ApiImplicitParam(name = "parentId",value = "家长序列号",required = false,dataTypeClass = Integer.class)
    })
    @GetMapping("/listpageparent")
    public CommonResult newListpage(int page,int size,String theme,Integer parentId){
        Map<String ,Object> map = new HashMap<>();
        map.put("data" ,diaryService.newListpage(page,size,theme,parentId));
        map.put("count",diaryService.newCount(theme,parentId));
        return CommonResult.success(map);
    }
    @SystemControllerLog(description = "成长日记添加")
    @ApiOperation(value = "家长添加日记")
    @PostMapping("/save")
    public CommonResult saveTask(@RequestBody Diary diary){
        Child child = new Child();
        child.setChildId(diary.getChild().getChildId());
        diary.setChild(child);
        return CommonResult.success(diaryService.saveDiary(diary));
    }
    @SystemControllerLog(description = "删除日记")
    @ApiOperation("删除日记信息")
    @GetMapping("/remove")
    public CommonResult remove(@RequestParam("diary_id") int diary_id){
        return CommonResult.success(diaryService.removeById(diary_id));
    }
    @SystemControllerLog(description = "修改日记")
    @ApiOperation("修改日记信息")
    @PostMapping("/update")
    public CommonResult update(@RequestBody Diary diary){
        return CommonResult.success(diaryService.update(diary));
    }
}
